﻿
@{
    ViewBag.Title = "edit";
    Layout = "~/Views/lib/_LayoutPageLib.cshtml";
}
<style>
    #border {
        margin: auto;
        width: 620px;
        height: 250px;
        border: 1px solid;
        padding-top: 10px;
    }
</style>
<script src="~/lib/js/jquery.min.js"></script>
<form class="layui-form">    
    <div class="layui-form-item" style="margin-top:30px">
        <label for="L_pass" class="layui-form-label">
            新的角色名称
        </label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" value="" placeholder="新的角色名称" id="rolesname">
        </div>        
    </div>
    <div>
        <div id="border">
            <div id="allroles">
                @foreach (var item in ViewBag.no)
                {
                    <input type="checkbox" id="@item.Id" name="newid" title="@item.Name" >
                }
            </div>            
        </div>
    </div>


    <div class="layui-form-item" style="margin-top:20px;margin-left:150px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">
                <i class="layui-icon">&#x1005;</i>立即添加
            </button>
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="anew">
                <i class="layui-icon">&#xe9aa;</i> 重置
            </button>
        </div>
    </div>

</form>


<script>

    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        $ = layui.jquery;
        form.on('submit(*)', function (data) {   //点击添加执行方法
            var thisid = $("#thisid").val();
            var thisname = $("#rolesname").val();
            var arr = [];
            for (var i = 0; i < $("#allroles").children().length ; i++) {
                if ($("#allroles").children()[i].checked == true) {
                    arr.push($("#allroles").children()[i].id);
                }
            }           
            //获取选中的功能
            if (thisname == "") {
                layer.msg("角色名称不能为空", { icon: 2, time: 2000, anim: 6 });
                return false;
            }
            if (arr.length <= 0) {
                layer.msg("至少选择一个权限", { icon: 2, time: 2000, anim: 6 });
                return false;
            }
            $.post("/Roles/Add", { Name: thisname, ModuleId: arr }, function (res) {
                if (res.success) {
                    layer.msg(res.msg, { icon: 1, time: 1500}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, time: 1500, anim: 6 });
                }
            })

            return false;
        });
        form.on('submit(anew)', function (data) {   //点击重置执行方法
            window.location.reload();
            return false;
        });

    });

</script>



